Add gtk_widget_snapshot_child
authorTimm Bäder <mail@baedert.org>
Fri, 6 Jan 2017 08:43:52 +0000 (09:43 +0100)
committerTimm Bäder <mail@baedert.org>
Sat, 7 Jan 2017 16:19:30 +0000 (17:19 +0100)
gtk/gtkboxgadget.c
gtk/gtkwidget.c
gtk/gtkwidgetprivate.h

index f331489b95f3dc27b57572a1ffa1abc87b7a369e..93d9d92d42b9ecc4bc3e8b597c99187644bd40ae 100644 (file)
@@ -536,7 +536,7 @@ gtk_box_gadget_snapshot (GtkCssGadget *gadget,
       GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, draw_index);
 
       if (GTK_IS_WIDGET (child->object))
-        gtk_container_snapshot_child (GTK_CONTAINER (owner), GTK_WIDGET (child->object), snapshot);
+        gtk_widget_snapshot_child (owner, GTK_WIDGET (child->object), snapshot);
       else
         gtk_css_gadget_snapshot (GTK_CSS_GADGET (child->object), snapshot);
     }
index bbf5f3ca16e6345c0e917d233e8698ca4020d4a7..8bebdfb04845842ab7088b65037551bc8afd3223 100644 (file)
@@ -15735,3 +15735,72 @@ gtk_widget_forall (GtkWidget   *widget,
       child = next;
     }
 }
+
+static void
+gtk_widget_get_translation_to_child (GtkWidget *widget,
+                                     GtkWidget *child,
+                                     int       *x_out,
+                                     int       *y_out)
+{
+  GtkAllocation allocation;
+  GdkWindow *window, *w;
+  int x, y;
+
+  /* translate coordinates. Ugly business, that. */
+  if (!_gtk_widget_get_has_window (widget))
+    {
+      _gtk_widget_get_allocation (widget, &allocation);
+      x = -allocation.x;
+      y = -allocation.y;
+    }
+  else
+    {
+      x = 0;
+      y = 0;
+    }
+
+  window = _gtk_widget_get_window (widget);
+
+  for (w = _gtk_widget_get_window (child); w && w != window; w = gdk_window_get_parent (w))
+    {
+      int wx, wy;
+      gdk_window_get_position (w, &wx, &wy);
+      x += wx;
+      y += wy;
+    }
+
+  if (w == NULL)
+    {
+      x = 0;
+      y = 0;
+    }
+
+  if (!_gtk_widget_get_has_window (child))
+    {
+      _gtk_widget_get_allocation (child, &allocation);
+      x += allocation.x;
+      y += allocation.y;
+    }
+
+  *x_out = x;
+  *y_out = y;
+}
+
+void
+gtk_widget_snapshot_child (GtkWidget   *widget,
+                           GtkWidget   *child,
+                           GtkSnapshot *snapshot)
+{
+  int x, y;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (_gtk_widget_get_parent (child) == widget);
+  g_return_if_fail (snapshot != NULL);
+
+  gtk_widget_get_translation_to_child (widget, child, &x, &y);
+
+  gtk_snapshot_translate_2d (snapshot, x, y);
+  gtk_widget_snapshot (child, snapshot);
+  gtk_snapshot_translate_2d (snapshot, -x, -y);
+}
index c19dd2a96636e72d1d76a23cbf8aec34f19f3c67..d4da81c08e5847b4002bd45afa787cc7127d7a0f 100644 (file)
@@ -304,6 +304,11 @@ void              gtk_widget_forall                        (GtkWidget
                                                             GtkCallback           callback,
                                                             gpointer              user_data);
 
+void              gtk_widget_snapshot_child                (GtkWidget   *widget,
+                                                            GtkWidget   *child,
+                                                            GtkSnapshot *snapshot);
+
+
 /* inline getters */
 
 static inline gboolean